<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>WS客户端Rose</title>
</head>
<body>
<section>
    <h1>WS客户端Rose</h1>
    <button type="button" onclick="socket.close()">下线</button>
    <button type="button" onclick="socket.send('大家好，我是Rose')">群发消息 "大家好，我是Rose"</button>
</section>

<script type="text/javascript">
    let socket;
    onload = () => {
        if (!WebSocket) {
            alert("当前浏览器不支持websocket..");
            return;
        }
        // 使用ws://协议连接S端，并传递rose的用户ID过去
        socket = new WebSocket("ws://localhost:5555/api/v1/danmu-server/2");
        socket.onopen = () => console.log("rose上线了");
        socket.onclose = () => console.log("rose下线了");
        socket.onerror = () => console.log("rose连接或通信异常");
        socket.onmessage = resp => console.log(resp['data']);
    };
</script>
</body>
</html>